
use serde::{Deserialize, Serialize};

#[derive(Debug,Serialize, Deserialize,Clone)]
pub struct Deptment {
    pub id: u32,
    pub name: String,
    pub parent_id: u32,
    pub parent_name: String,
}
impl Deptment {
    pub fn new(id:u32)->Self{
        Self{
            id,
            name: "".to_owned(),
            parent_id: 0,
            parent_name: "".to_owned(),
        }
    }
    pub fn from_vec(id:u32,vals: Vec<(u8, String)>) -> Self{
        let mut dept = Deptment::new(id);
        for (key, val) in vals {
            match key {
                0 => dept.name = val,
                1 => dept.parent_id = val.parse().unwrap_or(0),
                2 => dept.parent_name = val,
                _ => {}
            }
        }
        dept
    }
}
